package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.deepdesigner.pojo.DtsRegion;
import top.deepdesigner.service.DtsRegionService;

import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/21 星期三 22:45:05 <br/>
 */
@Service
public class DtsRegionServiceImpl extends ServiceImpl<BaseMapper<DtsRegion>, DtsRegion> implements DtsRegionService {
  @Override
  public Long getRegionCount() {
    return this.count();
  }

  @Override
  public List<DtsRegion> getRegionList(Integer page, Integer limit, String name, Integer code) {
    LambdaQueryWrapper<DtsRegion> wrapper = new LambdaQueryWrapper<>();
    wrapper.eq(code != null, DtsRegion::getCode, code)
        .like(!StringUtils.isEmpty(name), DtsRegion::getName, name);
    Page<DtsRegion> userPage = new Page<>(page, limit);
    return this.page(userPage, wrapper).getRecords();
  }
}
